package cn.shiro.shiroservice.jdbc;

import cn.shiro.shiroservice.common.utils.SqlSessionUtils;
import cn.shiro.shiroservice.moudle.db.mapper.DataBaseMapper;
import cn.shiro.shiroservice.moudle.db.service.impl.DatabaseServiceImpl;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.*;
import java.util.logging.Logger;

/**
 * &#064;Time 2024 一月 星期二 23:21
 *
 * @author ShangGuan
 */
@SpringBootTest
public class BackUpTablesCopy {

    @Test
    public void baskUp(){

    }
    public static void main(String[] args) {
        // JDBC 连接信息
        String jdbcUrl = "jdbc:mysql://localhost:3306";
        String username = "root";
        String password = "12345678";

        // SQL 查询语句（备份整个表）
        String tableName = "sys_role";
//        String selectQuery = "SELECT * FROM " + tableName;
        String selectQuery = "SHOW DATABASES";
        try {
            // 建立 JDBC 连接
            Connection connection = DriverManager.getConnection(jdbcUrl, username, password);
            Statement statement = connection.createStatement();
            // 执行查询
            ResultSet resultSet = statement.executeQuery(selectQuery);
            while (resultSet.next()){
                for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
                    String columnName = resultSet.getString(i);
                    System.out.println(columnName);
                }
            }

            // 关闭资源
            resultSet.close();
            statement.close();
            connection.close();
            System.out.println("Backup completed !");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
